var wordPattern = function(pattern, s) {
  let arr = s.split(' ');
  if(pattern.length !== arr.length) return false;
  let map = new Map();
  for(let i = 0; i < arr.length ; i++){
      if(map.has(pattern[i])){
          if(map.get(pattern[i]) !== arr[i]){
              return false;
          }
      }else{
          map.set(pattern[i],arr[i]);
      }
  }
  return true;
};
console.log(wordPattern(pattern = "abba", str = "dog cat cat fish"));